package com.ch05.service.impl;

import com.ch05.mapper.UserMapper;
import com.ch05.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author Kx
 * @Date 2025/4/28 10:06
 * @Version 1.0
 */
// @Component注解用于装配一个bean value属性用于设置bean的id, 如果不设置则使用当前类名将首字母改为小写作为id
//@Component("userService")
// 从3.0开始使用@Service注解标识业务层
@Service("userService")
// 可以用lombok自动生成一个带参的构造方法由spring来注入
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {
    // 持久层对象
    // 方式一: @Autowired注解用于自动注入属性
//    @Autowired
    private final UserMapper userMapper;

    /**
     * @author: kx
     * @date: 2025/4/28 15:44
     * @description: 方式二: 当有多个实现类可以结合@Qualifier注解指定注入的bean
    */
    /*public UserServiceImpl(@Qualifier("userMapper") UserMapper userMapper) {
        this.userMapper = userMapper;
    }*/

    /**
     * @author: kx
     * @date: 2025/4/28 15:49
     * @description: 当只有一个实现类的时候,可以直接使用@Autowired注解
    */
    /*@Autowired
    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }*/

    @Override
    public void save() {
        userMapper.add();
    }
}
